package com.controller;

import com.mypg.Manager;
import com.service.ManagerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpSession;

@RequestMapping("/other")
@Controller
public class OtherController {

    @Autowired
    ManagerService managerService;


    public String Img_Path="E:\\毕设有关\\上传的文件\\图片\\";
//    public String Img_Path="/www/myfile/gradute_db_relative/";



    @RequestMapping("/main_onload.do")
    @ResponseBody
    public void doMain_onload(HttpSession session){
        if(session.getAttribute("img_save_path")==null)
          session.setAttribute("img_save_path",Img_Path);

//        if(session.getAttribute("user_name")==null)
//            session.setAttribute("user_name","小明");
    }

    @RequestMapping("manager_login.do")
    @ResponseBody
    public int doManager_login(String manager_name,String manager_password,HttpSession session){
        Manager manager=managerService.selectManagerByManager_name(manager_name);
        if(manager==null){
            return 1;
        }else{
            if(!manager.getManager_password().equals(manager_password)){
                return 2;
            }
        }
        session.setAttribute("flag_manager",manager.getManager_name());
        return 0;
    }

    @RequestMapping("/out_login.do")
    @ResponseBody
    public void doOut_login(HttpSession session){

        session.removeAttribute("flag_manager");


    }

    @RequestMapping("/main_manager_info_init.do")
    @ResponseBody
    public Manager doMain_manager_info_init(HttpSession session){
        String manager_name= (String) session.getAttribute("flag_manager");
        return managerService.selectManagerByManager_name(manager_name);
    }

    @RequestMapping("/main_manager_info_update_password.do")
    @ResponseBody
    public int doMain_manager_info_update_password(String manager_password_raw,String manager_password_new,HttpSession session){
        String manager_name= (String) session.getAttribute("flag_manager");
        Manager manager=managerService.selectManagerByManager_name(manager_name);
        if(manager_password_raw.equals(manager.getManager_password())){
            managerService.updateManagerByManager_name(manager_name,manager_password_new);
            return 0;
        }else{
            return 1;
        }
    }
}
